package com.ruoyi.project.jiaqin.newsimg.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.newsimg.domain.NewsImg;
import com.ruoyi.project.jiaqin.newsimg.service.INewsImgService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 新闻图片Controller
 * 
 * @author LCL
 * @date 2021-10-11
 */
@Controller
@RequestMapping("/jiaqin/newsimg")
public class NewsImgController extends BaseController
{
    private String prefix = "jiaqin/newsimg";

    @Autowired
    private INewsImgService newsImgService;

    @RequiresPermissions("jiaqin:newsimg:view")
    @GetMapping()
    public String newsimg()
    {
        return prefix + "/newsimg";
    }

    /**
     * 查询新闻图片列表
     */
    @RequiresPermissions("jiaqin:newsimg:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewsImg newsImg)
    {
        startPage();
        List<NewsImg> list = newsImgService.selectNewsImgList(newsImg);
        return getDataTable(list);
    }

    /**
     * 导出新闻图片列表
     */
    @RequiresPermissions("jiaqin:newsimg:export")
    @Log(title = "新闻图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NewsImg newsImg)
    {
        List<NewsImg> list = newsImgService.selectNewsImgList(newsImg);
        ExcelUtil<NewsImg> util = new ExcelUtil<NewsImg>(NewsImg.class);
        return util.exportExcel(list, "newsimg");
    }

    /**
     * 新增新闻图片
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存新闻图片
     */
    @RequiresPermissions("jiaqin:newsimg:add")
    @Log(title = "新闻图片", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NewsImg newsImg)
    {
        return toAjax(newsImgService.insertNewsImg(newsImg));
    }

    /**
     * 修改新闻图片
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        NewsImg newsImg = newsImgService.selectNewsImgById(id);
        mmap.put("newsImg", newsImg);
        return prefix + "/edit";
    }

    /**
     * 修改保存新闻图片
     */
    @RequiresPermissions("jiaqin:newsimg:edit")
    @Log(title = "新闻图片", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NewsImg newsImg)
    {
        return toAjax(newsImgService.updateNewsImg(newsImg));
    }

    /**
     * 删除新闻图片
     */
    @RequiresPermissions("jiaqin:newsimg:remove")
    @Log(title = "新闻图片", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(newsImgService.deleteNewsImgByIds(ids));
    }
}
